import { http } from '@/utils/request'

// 图标信息
export interface Icon {
  id: number
  name: string
  category: string
  url: string
  svg_content?: string
  tags?: string
  sort: number
  is_active: boolean
}

// 加密方式
export interface EncryptMethod {
  value: string
  label: string
  description: string
}

// 系统配置
export interface SystemConfig {
  app_name: string
  app_version: string
  encrypt_methods: string[]
  max_devices_per_user: number
  password_expire_days: number
  auto_logout_minutes: number
  enable_biometric: boolean
  enable_backup: boolean
  [key: string]: any
}

// 版本信息
export interface VersionInfo {
  current_version: string
  latest_version: string
  has_update: boolean
  update_info: {
    title: string
    description: string
    force_update: boolean
    download_url: string
  }
}

// 应用信息
export interface AppInfo {
  app_name: string
  app_version: string
  company: string
  website: string
  email: string
  privacy_url: string
  terms_url: string
  features: string[]
}

// 健康检查
export interface HealthInfo {
  status: string
  timestamp: number
  version: string
  database: string
  cache: string
}

// 用户反馈
export interface FeedbackData {
  type: string
  content: string
  contact?: string
  device_info?: any
}

/**
 * 获取图标库
 */
export const getIcons = (category?: string) => {
  return http.get<Icon[]>('/system/icons', category ? { category } : undefined)
}

/**
 * 获取加密方式列表
 */
export const getEncryptMethods = () => {
  return http.get<EncryptMethod[]>('/system/encrypt-methods')
}

/**
 * 获取公开配置
 */
export const getPublicConfig = () => {
  return http.get<SystemConfig>('/system/public-config')
}

/**
 * 版本检查
 */
export const checkVersion = (currentVersion: string, platform: string) => {
  return http.get<VersionInfo>('/system/version', {
    version: currentVersion,
    platform
  })
}

/**
 * 获取应用信息
 */
export const getAppInfo = () => {
  return http.get<AppInfo>('/system/app-info')
}

/**
 * 健康检查
 */
export const healthCheck = () => {
  return http.get<HealthInfo>('/system/health')
}

/**
 * 用户反馈
 */
export const submitFeedback = (data: FeedbackData) => {
  return http.post('/system/feedback', data, {
    loading: true,
    loadingText: '提交中...'
  })
}